package com.alon.spring01.common.config.spring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @program: spring01
 * @description: spring bean工具类   实现ApplicationContextAware 设置上下文环境
 * @author: yulongguang
 * @create: 2019-05-15 14:46
 **/
public class SpringBeanUtil implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    public SpringBeanUtil() {
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringBeanUtil.applicationContext = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static Object getBean(String name) throws BeansException {
        return applicationContext.getBean(name);
    }
}
